package com.nit.vehicle.utils;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DBUtils {
	public static Connection con = null;
	public static Context ctx = null,envContext=null;
	public static DataSource ds = null;
	public static Connection getConnection() throws NamingException, SQLException{
		try {
			Context initContext = new InitialContext();
			DataSource ds = (DataSource)initContext.lookup("TestDB"); 
			System.out.println(ds);
			con = ds.getConnection();
			System.out.println(con);
		} catch (NamingException e) {
			//logging
			System.out.println("Namsing exception");
			throw e;
		} catch (SQLException e) {
			//logging
			System.out.println("sql exception");
			throw e;
		}
		return con;		
	}

}
